import http from "../utils/request"
import {PageRequestType, ResponseType, PageResponseType} from "../types/Response";
import {AxiosResponse} from "axios";

const apiPrefix:string = "/favorite";

export interface FavoriteType {
    // id
    id?:string|null|undefined
    // 用户id
    user_id?:string|null|undefined
    // 商品id
    goods_id?:string|null|undefined
    // 创建时间
    create_at?:any|null|undefined
    // 修改时间
    update_at?:any|null|undefined
}

export interface FavoritePageSearchType extends PageRequestType, FavoriteType {

}


export async function addFavorite(goodsId: string): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            goodsId
        },
        url: apiPrefix+'/add',
        method: 'get'
    })
}

export async function deleteFavorite(goodsId: string): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            goodsId
        },
        url: apiPrefix+'/delete',
        method: 'delete'
    })
}

export async function deleteFavoriteByIds(ids: string[]): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            ids
        },
        url: apiPrefix+'/batch',
        method: 'delete'
    })
}


export async function searchFavoriteById(id: string): Promise<AxiosResponse<ResponseType<FavoriteType>>> {
    return await http.request({
        params: {
            id
        },
        url: apiPrefix+'/id',
        method: 'get'
    })
}

export async function searchFavorite(params?: FavoriteType): Promise<AxiosResponse<ResponseType<FavoriteType[]>>> {
    return await http.request({
        params: params,
        url: apiPrefix,
        method: 'get'
    })
}

export async function searchFavoriteByPage(params: FavoritePageSearchType): Promise<AxiosResponse<ResponseType<PageResponseType<FavoriteType>>>> {
    return await http.request({
        params: params,
        url: apiPrefix+'/favoritePage',
        method: 'get'
    })
}


export async function updateFavoriteById(data: FavoriteType): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        data: data,
        url: apiPrefix,
        method: 'put'
    })
}
